<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class UaddressController extends BaseController {
	private $tbl;
	private $uid;
	public function _initialize(){
		session_start();
		$this->tbl='uadress';
		$this->model=D($this->tbl);
		parent::_initialize();
	}
    public function index(){
		$uid=I('get.id');
		$sql="select * from uadress where uid='{$uid}'";
		$res=M()->query($sql);
		$this->assign("list",$res);
		$this->assign("uid",$uid);
		$this->display();
		//parent::index($this->tbl);
    }
	public function	view(){
		$id=I('get.id');//获取id
	}
	public function mod(){//修改界面
		
		 parent::mod($this->tbl,"id");
	}
	public function update(){//修改
			$this->model=D($this->tbl);
			$data=I('post.');
			$user=$this->model->create($data);
			$position="Uaddress/Index/id/{$data['uid']}";
			if($user){
				$this->model->save();
				
				$this->success('更新成功！',U($position));
			}else{
				$this->error("更新失败！",U($position));
			}
		
	}
	public function delete(){//删除
		$this->model=D($this->tbl);
		$id=I('get.id');//内容，默认值
		$uid=I('get.uid');
		$data=$this->model->where("$id='{$id}'")->find();
		$position="Uaddress/Index/id/{$uid}";
		$result=$this->model->delete($id);
		if($result){
			$this->success('删除成功',U($position));//地址，内容				
		}else{
			$this->error('删除失败',U($position));//
		}
	}
	public function form(){//添加界面
			$uid=I('get.id');
			$this->assign("uid",$uid);
			parent::form($this->tbl);
	}
	public function add(){//添加
		$data=I('post.');
		$this->model=D($this->tbl);
		$position="Uaddress/Index/id/{$data['uid']}";
		//echo $position;exit;
		if($this->model->create($data)){
			$this->model->add();
			$this->success('增加成功！',U($position));
		}else{
			$this->error($this->model->getError());
			$this->error("增加失败！",U($position));
	}
	}
	public function search(){
		parent::search($this->tbl,"name","name");
	}
}